package com.bobochang.warehouse.dto;

import com.baomidou.mybatisplus.annotation.TableField;
import com.bobochang.warehouse.entity.Contract;
import com.bobochang.warehouse.entity.Product;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author LiY
 * 产品汇总表
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProductCollectDto {

    @TableField(exist = false)
    private Integer contactId;

    private String projectName;

    private String company;

    @TableField(exist = false)
    private Map<Product, BigDecimal> productBigDecimalMap;

    private Map<Integer, BigDecimal> productBigDecimalMap1;

    @JsonFormat(pattern = "yyyy-MM",timezone = "GMT+8")
    private Date date;

    private BigDecimal number;

    private Integer productId;

    /**
     * 备注
     */
    private String remark;

    public ProductCollectDto(List<Product> list){
        productBigDecimalMap = new HashMap<>();
        productBigDecimalMap1 = new HashMap<>();
        list.forEach(l -> {
            productBigDecimalMap.put(l, BigDecimal.valueOf(0));
            productBigDecimalMap1.put(l.getProductId(), BigDecimal.valueOf(0));
        });
    }

    public void setNumber(Integer productId, BigDecimal i){
        productBigDecimalMap.keySet().forEach(p -> {
            if(p.getProductId().equals(productId)){
                productBigDecimalMap.put(p,productBigDecimalMap.get(p).add(i));
            }
        });
    }

    public void setNumber1(Integer productId, BigDecimal i){
        BigDecimal temp = productBigDecimalMap1.get(productId).add(i);
        productBigDecimalMap1.put(productId, temp);
    }


}
